# @Time : 2020/6/25 15:48
# @Author : Fioman 
# @Phone : 13149920693
def tag(name, *content, cls=None, **attrs):
    """生成一个或多个HTML标签"""
    if cls is not None:
        attrs["class"] = cls

    if attrs:
        attr_str = ''.join(' %s="%s"' % (attr, value) for attr, value in sorted(attrs.items()))
    else:
        attr_str = ''

    if content:
        return "\n".join('<%s%s>%s</%s>' % (name, attr_str, c, name) for c in content)
    else:
        return '<%s%s />' % (name, attr_str)

t1 = tag('br')
print("t1 = {}".format(t1))
t2 = tag('p','hello')
print("t2 = {}".format(t2))
t3 = tag("p","hello","world")
print("t3 = {}".format(t3))
t4 = tag("p","hello",id=33)
print("t4 = {}".format(t4))
t5 = tag("p","hello","world",cls="sidebar")
print("t5 = {}".format(t5))
t6 = tag(content="testing",name='img')
print("t6 = {}".format(t6))

my_tag = {'name':'img',"title":'Sunset Boulevard','src':'sunset.jpg','cls':'framed'}
t7 = tag(**my_tag)
print("t7 = {}".format(t7))















